package markgame2dphys;

import java.awt.Color;

import net.phys2d.math.Vector2f;
import net.phys2d.raw.SpringJoint;

public class MarkGameSpringJoint extends MarkGameJoint{

	public SpringJoint joint;

	public MarkGameSpringJoint(MarkGameObject obj1, MarkGameObject obj2, Vector2f anchor1, Vector2f anchor2, float size, float minSize, float maxSize, float k) {

		super(new SpringJoint(obj1.body, obj2.body, anchor1, anchor2));
		//TODO adicionar restitution
		joint = (SpringJoint)super.joint;
		joint.setMinSpringSize(minSize);
		joint.setMaxSpringSize(maxSize);
		joint.setSpringSize(size);
		joint.setCompressedSpringConst(k);
		joint.setStretchedSpringConst(k);
		joint.setBrokenSpringConst(k);
	}

	public void paint(MarkGameGraphics g) {

		int r = 2;

		g.setColor(Color.RED);

		Vector2f anchor1 = MarkGameUtils.convertLocalToGlobal(joint.getBody1(), (Vector2f)joint.getLocalAnchor1());
		g.drawCircle(anchor1, r);

		Vector2f anchor2 = MarkGameUtils.convertLocalToGlobal(joint.getBody2(), (Vector2f)joint.getLocalAnchor2());
		g.drawCircle(anchor2, r);

		g.drawLine(anchor1, anchor2);

	}


}
